package com.shenmazong.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2022/1/13 16:43
 */

@Slf4j
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    private final String UPLOAD_DIR = "E:/var/images";


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String location = "file:///" + UPLOAD_DIR;
        log.info("localtion:"+location);

        // swagger文档对应的映射
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

        // 上传图片地址映射(实际目录需要已/结尾)
        registry.addResourceHandler("/img/**").addResourceLocations(location+"/");
    }
}
